package com.asr.testclient;

import com.asr.testclient.controller.MainController;
import com.asr.testclient.view.MainFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;

/**
 * 应用程序入口类
 * 初始化并启动ASR测试客户端
 */
public class Main {
    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        logger.info("Starting ASR Test Client application");
        
        // 使用SwingUtilities.invokeLater()在EDT中创建GUI
        SwingUtilities.invokeLater(() -> {
            try {
                // 设置系统外观
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                
                logger.info("Creating MainFrame and MainController");
                
                // 创建主窗口
                MainFrame mainFrame = new MainFrame();
                
                // 创建控制器
                MainController controller = new MainController(mainFrame);
                
                // 将控制器设置到视图
                mainFrame.setController(controller);
                
                // 显示主窗口
                mainFrame.setVisible(true);
                
                logger.info("Application started successfully");
                
            } catch (Exception e) {
                logger.error("Failed to start application", e);
                JOptionPane.showMessageDialog(
                    null,
                    "应用程序启动失败: " + e.getMessage(),
                    "启动错误",
                    JOptionPane.ERROR_MESSAGE
                );
                System.exit(1);
            }
        });
    }
}
